package com.sk.bilibili.view.diy;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.bumptech.glide.Glide;
import com.sk.bilibili.bean.Pendant;
import com.sk.bilibili.config.GlideApp;
import com.sk.bilibili.databinding.ViewAvatarBinding;

public class AvatarView extends ConstraintLayout {

    private ViewAvatarBinding bind;

    public AvatarView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        bind = ViewAvatarBinding.inflate(LayoutInflater.from(context), this, true);
    }

    public void setAvatar(String avatar){
        GlideApp.with(getContext()).load(avatar).header().into(bind.ivAvatar);
    }

    public void setPendant(String pendant){
        Glide.with(getContext()).load(pendant).into(bind.ivPendant);
    }

    public void setRes(String avatar, Pendant pendant){
        setAvatar(avatar);
        if(pendant==null){
            bind.ivPendant.setVisibility(INVISIBLE);
        }else {
            bind.ivPendant.setVisibility(VISIBLE);
            setPendant(pendant.getUrl());
        }
    }

}